using System.Collections.Generic;
using UnityEngine;

//怪物集合类
[System.Serializable]
public class GameBehaviorCollection
{
    List<GameBehavior> behaviors = new List<GameBehavior>();

    public bool IsEmpty => behaviors.Count == 0;

    public void Add(GameBehavior behavior)
    {
        behaviors.Add(behavior);
    }

    //更新整个集合
    public void GameUpdate()
    {
        for(int i = 0;i < behaviors.Count;i++)
        {
            if(!behaviors[i].GameUpdate())
            {
                int lastIndex = behaviors.Count - 1;
                behaviors[i] = behaviors[lastIndex];
                behaviors.RemoveAt(lastIndex);
                i -= 1;
            }
        }
    }

    public void Clear()
    {//回收所有怪物
        for(int i = 0;i<behaviors.Count;i++)
        {
            behaviors[i].Recycle();
        }
        behaviors.Clear();
    }
}